<template>
  <div class="my-tab-bar">
    <!-- tab-item 是底部导航的单元选框 -->
    <div 
    class="tab-item" 
    :class="{current:activeIndex === index}"
    @click="checkBtn(index, obj.componentName)"
    v-for="(obj, index) in tabBarList" :key='index'>
      <!-- 图标 -->
      <span class="iconfont" :class="[obj.iconText]"></span>
      <!-- 文字 -->
      <span>{{obj.text}}</span>
    </div>
  </div>
</template>



<script>
export default {
  data(){
    return{
      activeIndex: 0 // 高亮元素下标
    }
  },
  props:{
    tabBarList:{
      type: Array,
      default:() => [],
      required:true, // 一般不写
      validator(value){ // 校验父组件传递过来的数据的规则 - 一般不写
        // value 父组件传过来的值
        // 传过来的数值, 只能有2-5个元素
        return(value.length > 2  && value.length <= 5 )
      }
    }
  },
  methods:{
    checkBtn(index, name){
      this.activeIndex = index
      this.$emit('changeConName', name)
    }
  }
}
</script>

<style lang="less" scoped>
.my-tab-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: #ca1dff;
  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
    
.current {
  color: #1d7bff;
}
</style>